<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\cdc;

use app\enum\CdcEnum;
use app\model\mongo\MongoSyncModel;
use app\service\BaseService;

final class StatService extends BaseService
{
    protected int $mediaId = 0;

    protected int $taskType = 0;

    private ?BaseService $service;

    public function __construct(int $mediaId = 0, int $taskType = 0)
    {
        $this->mediaId = $mediaId;
        $this->taskType = $taskType;
    }

    /**
     * 获取数据汇总服务
     *
     * @return bool
     */
    public function getObject(): bool
    {
        $className = CdcEnum::getServiceClassNames($this->mediaId, 'stat', $this->taskType);
        if (! $className) {
            return self::setError('获取数据汇总服务失败');
        }
        $this->service = new $className();
        return true;
    }

    /**
     * 运行修复.
     * @param MongoSyncModel $model 中间表模型
     */
    public function run(MongoSyncModel $model): bool
    {
        return $this->service->runStat($model);
    }

    public function delLog(array $params = [])
    {
        return $this->service->delLog($params);
    }
}
